﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Control_InsertEmployeeControl : System.Web.UI.UserControl
{
    ListAndProcessData ws = new ListAndProcessData();

    protected void Page_Load(object sender, EventArgs e)
    {
        var groupaccount = ws.loadGroupName();
        foreach (var item in groupaccount)
        {
            DropDownList2.Items.Add(item.Groupname);
        }
    }
    protected void btnAdd_Click1(object sender, EventArgs e)
    {
        bool a = false;
        bool b = ws.validateCoincisiveLoginName(txtLoginName.Text);
        bool c = ws.validateCoincisiveEmail(txtEmail.Text);


        if(b == false || c == false){
            Response.Redirect("Loi.aspx");
        }
        if (DropDownList1.SelectedValue == "Male" && DropDownList2.SelectedValue == "admin" )
        {
            a = ws.InsertEmployee("1", txtLoginName.Text, "", txtFullNameEmployee.Text, txtAge.Text, 0, txtAddress.Text, txtPhone.Text, txtEmail.Text, txtQualification.Text);
            
        }
        if (DropDownList1.SelectedValue == "Male" && DropDownList2.SelectedValue == "mod")
        {
            a = ws.InsertEmployee("2", txtLoginName.Text, "", txtFullNameEmployee.Text, txtAge.Text, 0, txtAddress.Text, txtPhone.Text, txtEmail.Text, txtQualification.Text);

        }

        if (DropDownList1.SelectedValue == "FeMale" && DropDownList2.SelectedValue == "admin")
        {
            a = ws.InsertEmployee("1", txtLoginName.Text, "",txtFullNameEmployee.Text, txtAge.Text, 1, txtAddress.Text, txtPhone.Text, txtEmail.Text, txtQualification.Text);
        }

        if (DropDownList1.SelectedValue == "FeMale" && DropDownList2.SelectedValue == "mod")
        {
            a = ws.InsertEmployee("2", txtLoginName.Text, "", txtFullNameEmployee.Text, txtAge.Text, 1, txtAddress.Text, txtPhone.Text, txtEmail.Text, txtQualification.Text);

        }

        if (a == true)
        {
            Response.Redirect("Employee_Admin.aspx");

        }
        else
        {
            Response.Redirect("Default3.aspx");
        }
    }
    protected void btnreset_Click(object sender, EventArgs e)
    {
    }
}